package cn.edu.cqvie.cloud.controller;

import cn.edu.cqvie.cloud.conf.CloudConf;
import cn.edu.cqvie.cloud.remote.DemoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private CloudConf conf;

    @Autowired
    private DemoService demoService;

    @GetMapping("/index")
    public String demo() throws InterruptedException {
        Thread.sleep(5000);
        return conf.getHost() + " say: hello demo!";
    }

    @GetMapping("/index2")
    public String demo2() {
        long start = System.currentTimeMillis();
        String demo = demoService.demo();
        long end = System.currentTimeMillis();
        log.info(demo + " cost time: " + (end - start) + "ms");
        return demo + " cost time: " + (end - start) + "ms";
    }
}
